package my2Cents.tools;

import net.phys2d.raw.Body;
import net.phys2d.raw.Joint;
import net.phys2d.raw.SpringJoint;
import my2Cents.Winch;
import my2Cents.properties.CheckBox;
import my2Cents.properties.KeyAssign;
import my2Cents.properties.Property;
import my2Cents.properties.Slider;

public class WinchTool extends RopeTool {
	private int fkey = -1;
	private int rkey = -1;
	private float forwardSpeed = 5;
	private float reverseSpeed = 5;
	
	public WinchTool() {
		setName("Winch");
		setDescription("Click and draw out a line between\n" +
				"two objects, or one object and the screen\n" +
				"to create a constraint.\n\n" +
				"Assign keys to the expand and retract actions\n" +
				"before creating a winch.");
		
		KeyAssign forwardKey = new KeyAssign("Expand") {
			public void valueChanged(int value, char ch) {
				fkey = value;
			}
		};
		addProperty(forwardKey);
		
		KeyAssign backwardKey = new KeyAssign("Retract") {
			public void valueChanged(int value, char ch) {
				rkey = value;
			}
		};
		addProperty(backwardKey);
		
		Property p = new Slider("Expand Speed",5,1,50,5,true) {
			public void valueChanged(int value) {
				forwardSpeed = value;
			}
		};
		addProperty(p);
		
		p = new Slider("Retract Speed",5,1,50,5,true) {
			public void valueChanged(int value) {
				reverseSpeed = value;
			}
		};
		addProperty(p);
		removeProperty(4);
	}
	
	protected Joint createConstraint(Body b1, Body b2) {
		float len = start.distance(end);
		Joint j = new Winch(b1,b2,start,end); 
				Winch x = (Winch) j;
				x.setRigid(makeRigid);
				x.setLength(len + extraLength);
				x.setForwardCode(fkey);
				x.setReverseCode(rkey);
				x.setForwardSpeed(forwardSpeed/10);
				x.setReverseSpeed(reverseSpeed/10);

		return j;
	}
}
